package com.cn.admin.controller;

import com.cn.admin.controller.api.ScenicAPI;
import com.cn.admin.vo.product.*;
import com.cn.api.ScenicCoreService;
import com.cn.api.ScenicSortCoreService;
import com.cn.common.parameter.Paging;
import com.cn.common.result.Result;
import com.cn.dto.ScenicDTO;
import com.cn.dto.ScenicSortDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/back/scenic")
@Api(tags = "后台管理景区")
/**
 * 景区信息的crud
 * 后台管理系统
 */
public class ScenicController implements ScenicAPI {
    @Resource
    private ScenicCoreService scenicCoreService;
    @Resource
    private ScenicSortCoreService scenicSortCoreService;

    @ApiOperation(value = "添加景区")
    @PostMapping("/add")
    @ResponseBody
    @Override
    public Result add(AddScenicVO addScenicVO) {
        ScenicDTO scenicDTO = new ScenicDTO();
        int result = 0;

        scenicDTO.setNames(addScenicVO.getNames());//景区名称
        scenicDTO.setSorts(addScenicVO.getSorts());//景区分类id
        scenicDTO.setIntroduces(addScenicVO.getIntroduces());//景区介绍
        scenicDTO.setMaps(addScenicVO.getMaps());//景点分布图
        scenicDTO.setServiceTime(addScenicVO.getServiceTime());//景区营业时间
        scenicDTO.setDetails(addScenicVO.getDetails());//景区详情
        scenicDTO.setGrade(addScenicVO.getGrade());//景区等级
        scenicDTO.setLongitude(addScenicVO.getLongitude());//景区所在经度
        scenicDTO.setLatitude(addScenicVO.getLatitude());//景区所在纬度
        scenicDTO.setDetailAddress(addScenicVO.getDetailAddress());//景区详细地址
        scenicDTO.setProvince(addScenicVO.getProvince());//景区所在省
        scenicDTO.setCity(addScenicVO.getCity());//景区所在市
        scenicDTO.setSuppliers(addScenicVO.getSuppliers());//供应商
        scenicDTO.setNotification(addScenicVO.getNotification());//入园须知
        result = scenicCoreService.add(scenicDTO);
        if (result == 1){
            return Result.success(null,"景区添加成功");
        }else{
            return Result.failed("景区添加失败");
        }

    }

    @ApiOperation(value = "删除景区")
    @GetMapping(value = "/delete")
    @ResponseBody
    @Override
    public Result delete(DelectScenicVO delectScenicVO) {
        log.info("\n应用层（管理员）：景区删除");
        int result = scenicCoreService.delete(delectScenicVO.getId());

        if (result==1){
            return Result.success(null,"删除成功");
        }else {
            return Result.success(null,"删除失败");
        }
    }

    @ApiOperation(value = "查询所有景区")
    @GetMapping(value = "/findAll")
    @ResponseBody
    @Override
    public Result<List<FindAllScenicVO>> findAll(Paging paging) {
        scenicCoreService.findAll(paging);
        return null;
    }

    @ApiOperation(value = "根据id查询景区信息")
    @GetMapping(value = "/findById")
    @ResponseBody
    @Override
    public Result<FindAllScenicVO> findById(DelectScenicVO delectScenicVO) {
        return null;
    }

    @ApiOperation(value = "修改景区信息")
    @PostMapping("/update")
    @ResponseBody
    @Override
    public Result update(AddScenicVO addScenicVO) {
        return null;
    }

    @ApiOperation(value = "查询所有景区分类")
    @GetMapping("/querySort")
    @ResponseBody
    @Override
    public Result<List<RScenicSortVO>> querySort() {
        log.info("\n应用层：景区分类*******************************************");
        List<RScenicSortVO> rScenicSortVOList = new ArrayList<>();
        List<ScenicSortDTO> scenicSortDTOList = new ArrayList<>();
        scenicSortDTOList = scenicSortCoreService.findAll();

        for (ScenicSortDTO scenicSortDTO1 : scenicSortDTOList){
            RScenicSortVO rScenicSortVO = new RScenicSortVO();
            rScenicSortVO.setId(scenicSortDTO1.getId());
            rScenicSortVO.setNames(scenicSortDTO1.getNames());
            rScenicSortVOList.add(rScenicSortVO);
        }
        return Result.success(rScenicSortVOList);
    }
}
